home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Key / KeyControl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-23  |  8.2 KB  |  312 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     keycontrol.c
  5.  
  6.     DESCRIPTION
  7.     interface for keyboard control from main
  8.     Handle keyboard related stuff such as keyboard mappings. Every
  9.     time a key is pressed, KEYCTL() is called with the code. KEYCTL()
  10.     remembers which qualifier keys are currently held down, and when a
  11.     non-qualifier key is pressed finds the hash entry for the key.    If
  12.     no hash entry exists (e.g. you type a normal 'a') the default
  13.     keymap is used.
  14.  
  15.     NOTES
  16.     Amiga-specific & [X]DME-specific
  17.     depends on macro-language
  18.  
  19.     BUGS
  20.  
  21.     TODO
  22.     we might enable deadkeys on our own - shall we do this ?
  23.         that would be done with a command redefining a
  24.         variable that is used instead of NO_KEYS_PRESSED
  25.  
  26.     EXAMPLES
  27.  
  28.     SEE ALSO
  29.  
  30.     INDEX
  31.  
  32.     HISTORY
  33.     15-Dez-92  b_null created
  34.     16-Dez-92  b_null documented
  35.     $Date: 94/07/06 12:06:48 $ last update
  36.  
  37. ******************************************************************************/
  38.  
  39. /**************************************
  40.         Includes
  41. **************************************/
  42. #define  KEY_INTERNAL
  43. #include "defs.h"
  44.  
  45.  
  46. /**************************************
  47.         Globale Variable
  48. **************************************/
  49. Prototype void keyctl (struct IntuiMessage *, int, ULONG);  /* PATCH_NULL [14 Feb 1993] : changed to void */
  50.  
  51.  
  52. /**************************************
  53.       Interne Defines & Strukturen
  54. **************************************/
  55. #define NO_KEYS_PRESSED 0x00000000  /* we might write 0C0? for accents */
  56.  
  57. /* some hardcoded keys on Amiga Keyboard - look also in keycodes */
  58. /*    UARGGH! We must blend out shift, alt, etc, and for there */
  59. /*    is no way to find out, which key is a qualifier, we use  */
  60. /*    them hardcoded, so hat piece of code is non-portable     */
  61.  
  62. #define CLShift 0x60
  63. #define CRShift 0x61
  64. #define CCaps    0x62
  65. #define CCtrl    0x63
  66. #define CLAlt    0x64
  67. #define CRAlt    0x65
  68. #define CLAmiga 0x66
  69. #define CRAmiga 0x67
  70.  
  71. #define CSPC    0x40
  72. #define CB_S    0x41 /* always ? */
  73. #define CTab    0x42
  74. #define CENT    0x43
  75. #define CRET    0x44
  76.  
  77.  
  78.  
  79. /**************************************
  80.         Interne Variable
  81. **************************************/
  82. /* nothing */
  83.  
  84. /**************************************
  85.        Interne Prototypes
  86. **************************************/
  87.  
  88.  
  89. /*****************************************************************************
  90.  
  91.     NAME
  92.     keyctl
  93.  
  94.     PARAMETER
  95.     struct IntuiMessage *    im
  96.     int            code
  97.     ULONG            qual
  98.  
  99.     RESULT
  100.     -/-
  101.  
  102.     RETURN
  103.     void
  104.  
  105.     DESCRIPTION
  106.     reaction on a key-information
  107.  
  108.     NOTES
  109.  
  110.     BUGS
  111.  
  112.     EXAMPLES
  113.  
  114.     SEE ALSO
  115.  
  116.     INTERNALS
  117.     erzeuge die mit der msg verbundenen keycodes
  118.     und qualifiers
  119.     suche dann nach einer map dafuer
  120.     //falls es keine gab, benutze wenn moeglich die
  121.     //system-belegung als macro
  122.  
  123.     HISTORY
  124.     15-Dez-92  b_null moved here & modified
  125.     16.Dez.92  b_null documented
  126.     28.Dez.92  b_null added support for NO dead-keys
  127.     27-06-94   b_null debugged - what a hack... =8-(
  128.     20-10-94   b_noll cleaned up a bit
  129.  
  130. ******************************************************************************/
  131.  
  132. void keyctl (struct IntuiMessage * im, int code, ULONG qual)
  133. {
  134. /* PATCH_DEAD 28-Dez-92 : this is the boolean flag for disabling Deadkeys, */
  135. /*              if the last non-"up"-key initiated a macrocall   */
  136.     static  WORD   last_displayed = 0;
  137.         UBYTE  buf[LINE_LENGTH];
  138.         UWORD  c2;
  139.         WORD   blen = 0;
  140.         int    ext2;
  141.         HASH  *hash;
  142.         struct keyspec ks;
  143.         BOOL   defaulting = FALSE;
  144. /* static int id=0; */
  145.  
  146.     code &= 0xFF;            /* shorten code to one byte */
  147.  
  148. /* ++id; */
  149. /* printf ("\n[%04x] LD=%d iaddr %08lx->%08lx (A)\n", id, last_displayed, (im)?im->IAddress:NULL, (im)? *(long*)im->IAddress: 0L); */
  150.  
  151.  
  152. #if defined(PATCH_FILTER)
  153.     /*
  154.     **    --- Before executing the keystroke,
  155.     **        check if a filter is active and if the key can pass the filter
  156.     */
  157.     if ((key_filter != 0) && (filter_key (code) != 0)) {
  158.     return;
  159.     } /* if */
  160. #endif /* PATCH_FILTER */
  161.  
  162.  
  163.     /*
  164.     **    --- Before evaluating the key's Qualifiers,
  165.     **        append the extended Qualifiers to the pressed ones
  166.     */
  167.     ext2 =  ext_qualifiers;
  168.     qual = (qual & 0xF000FFFF) | ext2;
  169.  
  170.     if (im) {
  171.     UWORD oldQual = im->Qualifier;
  172.     long  dummy_prev[1];
  173.     long *inter_iaddr;
  174.  
  175. //printf ("[    ] LD=%d iaddr %08lx->%08lx code/qual %02x/%04x ic/xq %02x/%08lx (E)\n", last_displayed, im->IAddress, *((long*)im->IAddress), im->Code, im->Qualifier, code, ext_qualifiers);
  176.  
  177.     /* ---- if necessary hide the last pressed keys */
  178.     inter_iaddr = im->IAddress;
  179.     if (last_displayed) {
  180.         dummy_prev[0]  = NO_KEYS_PRESSED;
  181.         im->IAddress   = dummy_prev;
  182. //          if (!(code & IECODE_UP_PREFIX)) {
  183. //puts ("clearing eta");
  184. //        last_displayed = 0;
  185. //          }
  186.     } /* if */
  187.  
  188.  
  189.     im->Qualifier = (oldQual & ~IEQUALIFIER_REPEAT) | (0xFFFF & ext2);  /* == ... & 0xF000FFFF | ext2 -> === qual ohne extended */
  190.     blen          = DeadKeyConvert (im, buf+1, 254, NULL);
  191.  
  192.     /* ---- restore the old values (that is not necessary, since we */
  193.     /*    are using a copy of im, but it makes code reusable    */
  194.     im->Qualifier = oldQual;
  195.     im->IAddress = inter_iaddr;
  196.  
  197.     /* ---- this key can be displayed, it is no deading key */
  198.     if (blen && !(code & IECODE_UP_PREFIX)) {
  199. //puts ("setting zeta");
  200.         last_displayed = 1;
  201.  
  202.         /* ---- only the Perm-quals stay valid */
  203.         ext_qualifiers &= 0x07000000;
  204.     } /* if no up-msg */
  205.  
  206.     /* ---- surround the bufferstring w/ quotes in */
  207.     /*    order to create a XDME write command   */
  208.     if (blen < 0) {
  209.         return;
  210.     } else if (blen == 1) {
  211.         buf[0] = '\'';
  212.         buf[2] = 0;
  213.     } else if (blen) {
  214.         buf[0] = '`';
  215.         buf[blen+1] = '\'';
  216.     } else {
  217.         buf[0] = 0;
  218.         buf[1] = 0;
  219.     } /* if */
  220.     } /* if */
  221.  
  222.  
  223.     /* ---- create the xdme key information */
  224.     c2             = iqual2qual (qual, blen, buf, code);
  225.     //code        &= ~IECODE_UP_PREFIX;
  226.     ks.ks_code         = code & ~IECODE_UP_PREFIX;
  227.     ks.ks_qualifiers = c2;
  228.     ks.ks_qualmask   = QUALMASK;
  229.  
  230. /* the following construct was added for [X]DME only to allow deletion on returnoverride */
  231. #   ifdef NOT_DEF
  232.     /* that long version disables not only return but also backspace and space */
  233.     if (GETF_COMLINEMODE(Ep) && c2 == 0) {
  234.         char * str = NULL;
  235.         switch (code) {
  236.         case CRET: str = "return";  break;
  237.         case CSPC: str = "( )";     break;
  238.         case CB_S: str = "bs";      break;
  239.         } /* switch */
  240.         if (str) {
  241. //puts ("setting epsilon");
  242.         last_displayed    =       1;
  243.         ext_qualifiers &= 0x07000000;
  244.         strcpy (buf, str);
  245.         do_command (buf);   /* PATCH_NULL [14 Feb 1993] : added */
  246.         return;
  247.         } /* if */
  248.     } /* if comline without quals */
  249. #   else
  250.     /* that short version only disables return */
  251.     if (GETF_COMLINEMODE(Ep) && code == CRET && c2 == 0) {
  252. //puts ("setting delta");
  253.         last_displayed  =           1;
  254.         ext_qualifiers &= 0x07000000;
  255.  
  256.         strcpy (buf, "return");
  257.         do_command (buf);       /* PATCH_NULL [14 Feb 1993] : added */
  258.         return;
  259.     } /* if */
  260. #   endif
  261.  
  262.  
  263.     hash = findhash (currenthash(), &ks, im? buf: NULL, &defaulting);
  264.  
  265. #ifndef Key_NoDefExt
  266. #define Key_NoDefExt 1
  267. #endif
  268.     DEFFLAG( 21-10-94, Key_NoDefExt, 0 )
  269.  
  270.     /* ---- we need not expand into nothing */
  271.     if (!hash || (defaulting && ((blen <= 0) || ((c2 & 0x7700) && Key_NoDefExt)))) {
  272.  
  273.     /* ---- ignore Upstrokes & Quals in last_displayed         */
  274.     /*    UARGGH! We must blend out shift, alt, etc, and for there */
  275.     /*    is no way to find out, which key is a qualifier, we use  */
  276.     /*    them hardcoded, so hat piece of code is non-portable     */
  277.     if (!(code & IECODE_UP_PREFIX) && !((code >= CLShift) && (code <= CRAmiga))) {
  278. //puts ("clearing gamma");
  279.         last_displayed = 0;
  280.     } /* if */
  281.     return;
  282.     } /* if */
  283.  
  284.     /*
  285.      *    Use hash entry only if not in command line mode, or if the
  286.      *    entry does not correspond to an alpha key.
  287.      */
  288.  
  289.     if (c2 || !GETF_COMLINEMODE(Ep) || blen > 1 || !CtoA(code & ~IECODE_UP_PREFIX)) {
  290. //puts ("setting beta");
  291.     ext_qualifiers &= 0x07000000;
  292.     last_displayed    =       1;
  293.     strcpy (buf, hash->comm);
  294.     do_command (buf);
  295.     } else {
  296.     if (blen > 0) {
  297. //puts ("setting alpha");
  298.         ext_qualifiers &= 0x07000000;
  299.         last_displayed  =           1;
  300.         do_command (buf);
  301.     } /* if */
  302.     } /* if */
  303.  
  304. } /* keyctl */
  305.  
  306.  
  307.  
  308.  
  309. /******************************************************************************
  310. *****  ENDE keycontrol.c
  311. ******************************************************************************/
  312.